package com.example.lancooznbk.utils;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.AnimationDrawable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.andview.refreshview.callback.IHeaderCallBack;
import com.example.lancooznbk.R;

/**
 * Created by Administrator on 2018/3/30.
 */

public class CustomGifHeader extends LinearLayout implements IHeaderCallBack {
    private TextView mHintTextView;
    private ImageView animation_iv;

    public CustomGifHeader(Context context) {
        super(context);
        setBackgroundColor(Color.parseColor("#f3f3f3"));
        initView(context);
    }

    /**
     * @param context
     * @param attrs
     */
    public CustomGifHeader(Context context, AttributeSet attrs) {
        super(context, attrs);
        initView(context);
    }

    private void initView(Context context) {
        LayoutInflater.from(context).inflate(R.layout.custom_gif_header, this);
        animation_iv = (ImageView) findViewById(R.id.animation_iv);
//        mHintTextView = (TextView) findViewById(R.id.gif_header_hint);
//        animation_iv.setVisibility(View.GONE);
        animation_iv.setImageResource(R.drawable.refresh_loading);

    }


    public void setRefreshTime(long lastRefreshTime) {
    }

    public void hide() {
        setVisibility(View.GONE);
    }

    public void show() {
        setVisibility(View.VISIBLE);
    }

    public void onStateNormal() {
//        mHintTextView.setText(R.string.xrefreshview_header_hint_normal);
        animation_iv.setImageResource(R.drawable.refresh_loading);
//        AnimationDrawable animationDrawable = (AnimationDrawable) animation_iv.getDrawable();
//        animationDrawable.stop();
    }

    public void onStateReady() {
//        mHintTextView.setText(R.string.xrefreshview_header_hint_ready);
        animation_iv.setImageResource(R.drawable.refresh_loading);
        AnimationDrawable animationDrawable = (AnimationDrawable) animation_iv.getDrawable();
        animationDrawable.start();
    }

    public void onStateRefreshing() {
//        mHintTextView.setText(R.string.xrefreshview_header_hint_refreshing);
        animation_iv.setImageResource(R.drawable.refresh_loading);
        AnimationDrawable animationDrawable = (AnimationDrawable) animation_iv.getDrawable();
        animationDrawable.start();

    }

    public void onStateFinish(boolean success) {
        animation_iv.setImageResource(R.drawable.refresh_loading);
        AnimationDrawable animationDrawable = (AnimationDrawable) animation_iv.getDrawable();
        animationDrawable.stop();
    }

    public void onHeaderMove(double headerMovePercent, int offsetY, int deltaY) {
        //
    }

    //回头布局的高度
    @Override
    public int getHeaderHeight() {
        int asdasd = getMeasuredHeight();
        Log.e("aaaa","aa"+asdasd);
        return getMeasuredHeight();
    }
}
